package com.jetpackframework.rxmvvm;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.jetpackframework.base.BaseActivity;
import com.jetpackframework.ioc.IViewBind;


/**
 * 利用rxjetpack构建的mvvm
 * @param <VM>
 * @param <V>
 */
public abstract class BaseRxMvvmActivity<VM extends ViewModel,V extends IViewBind> extends BaseActivity<V> implements IViewModelProvider{
    private ViewModelProvider viewModelProvider;
    protected VM viewmodel;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewModelProvider = new ViewModelProvider(this);
        viewmodel = viewModelProvider.get(getViewModelClass());
        getLifecycle().addObserver(viewmodel);

    }

    public ViewModelProvider getViewModelProvider(){
        return viewModelProvider;
    }
    public abstract Class<VM> getViewModelClass();
}
